﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZillowApiClient
{
    internal class AppConfig
    {
        internal string ZillowApiId
        {
            get { return ConfigurationManager.AppSettings.Get("ZillowApiId"); }
            set
            {
                ConfigurationManager.AppSettings.Remove("ZillowApiId");
                ConfigurationManager.AppSettings.Add("ZillowApiId", value);
            }
        }

        internal string InputPath
        {
            get { return ConfigurationManager.AppSettings.Get("InputPath"); }
            set
            {
                ConfigurationManager.AppSettings.Remove("InputPath");
                ConfigurationManager.AppSettings.Add("InputPath", value);
            }
        }

        internal string OutputPath
        {
            get { return ConfigurationManager.AppSettings.Get("OutputPath"); }
            set
            {
                ConfigurationManager.AppSettings.Remove("OutputPath");
                ConfigurationManager.AppSettings.Add("OutputPath", value);
            }
        }

        internal int InputHeaderLines
        {
            get
            {
                if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings.Get("InputHeaderLines")))
                    return 1;

                return Int32.Parse(ConfigurationManager.AppSettings.Get("InputHeaderLines"));
            }
            set
            {
                ConfigurationManager.AppSettings.Remove("InputHeaderLines");
                ConfigurationManager.AppSettings.Add("InputHeaderLines", value.ToString());
            }
        }

        internal bool IncludeOutputHeader
        {
            get { return ConfigurationManager.AppSettings.Get("IncludeOutputHeader") == "true"; }
            set
            {
                ConfigurationManager.AppSettings.Remove("IncludeOutputHeader");
                ConfigurationManager.AppSettings.Add("IncludeOutputHeader", value == true ? "true" : "false");
            }
        }

        internal int HttpTimeout
        {
            get
            {
                if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings.Get("HttpTimeout")))
                    return 1;

                return Int32.Parse(ConfigurationManager.AppSettings.Get("HttpTimeout"));
            }
            set
            {
                ConfigurationManager.AppSettings.Remove("HttpTimeout");
                ConfigurationManager.AppSettings.Add("HttpTimeout", value.ToString());
            }
        }

        internal int PauseInterval
        {
            get
            {
                return string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings.Get("PauseInterval")) ? 1 : Int32.Parse(ConfigurationManager.AppSettings.Get("PauseInterval"));
            }
            set
            {
                ConfigurationManager.AppSettings.Remove("PauseInterval");
                ConfigurationManager.AppSettings.Add("PauseInterval", value.ToString());
            }
        }
    }
}